package com.example.javabasic.thread.classtwo.lock.demo2;

public class Door {
    private static int num = 0;
    private String name = "名字:";
    private String address = "地址:";


    public synchronized void pass(String name, String address) {
        num++;
        this.name = name;
        this.address = address;
        check();
    }

    private void check() {
        if(this.name.charAt(0)!= this.address.charAt(0)){
            System.out.println(toString());
        }
    }

    @Override
    public String toString(){
        return "No."+num+","+name+":"+address;
    }
}
